package com.ag.zrt.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;


import com.ag.common.BaseAction;
import com.ag.zrt.service.InformationService;
import com.ag.bean.TbInformation;
@Controller("searchOrFindInformationAction")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class SearchOrFindInformationAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1634615488647365353L;
	@Resource(name = "InformationService")
	private InformationService informationService;

	private List<TbInformation> infoList;
	private String searchTitle = "";
	private String searchDate = "";
	private String searchType = ""; // 查找类型 0 为全部
	private int searchRatify; // 审核状态, 1为待审，2为通过，3为不通过,0为全部
	private int searchRead = 2; // 阅读状态 0为未读，1为已读，2为全部
	private String searchArea = ""; // 查找范围
	private int currentPage; // 当前页
	private int nextOrPrev = 1; // 下一页或上一页,0为上一页，1为下一页
	private int sortWay = 100; // 排序标志，100代表按日期排序（默认），101代表类型，102代表审核状态
	private int totalPage; // 总页数
	private int newInfo; // 未读信息总数
	private int all; // 符合条件的简报总数 

	public int getAll() {
		return all;
	}

	public int getNewInfo() {
		return newInfo;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public int getSortWay() {
		return sortWay;
	}

	public void setSortWay(int sortWay) {
		this.sortWay = sortWay;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getNextOrPrev() {
		return nextOrPrev;
	}

	public void setNextOrPrev(int nextOrPrev) {
		this.nextOrPrev = nextOrPrev;
	}

	public List<TbInformation> getInfoList() {
		return infoList;
	}

	public String getSearchArea() {
		return searchArea;
	}

	public String getSearchDate() {
		return searchDate;
	}

	public void setSearchDate(String searchDate) {
		this.searchDate = searchDate;
	}

	public int getSearchRead() {
		return searchRead;
	}

	public String getSearchTitle() {
		return searchTitle;
	}

	public String getSearchType() {
		return searchType;
	}

	public void setInformationService(InformationService informationService) {
		this.informationService = informationService;
	}

	public void setSearchArea(String searchArea) {
		this.searchArea = searchArea;
	}

	public int getSearchRatify() {
		return searchRatify;
	}

	public void setSearchRatify(int searchRatify) {
		this.searchRatify = searchRatify;
	}

	public void setSearchRead(int searchRead) {
		this.searchRead = searchRead;
	}

	public void setSearchTitle(String searchTitle) {
		this.searchTitle = searchTitle;
	}

	public void setSearchType(String searchType) {
		this.searchType = searchType;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub

		infoList = informationService.findOrSearchByPage(searchTitle,
				searchDate, searchType, searchRatify, searchRead, searchArea,
				currentPage, nextOrPrev, sortWay);

		/*
		 * System.out.println("标题 " + searchTitle); System.out.println("日期" +
		 * searchDate); System.out.println("类型" + searchType);
		 * System.out.println("审核" + searchRatify); System.out.println("阅读" +
		 * searchRead); System.out.println("范围" + searchArea);
		 * System.out.println("当前页" + currentPage); System.out.println("上/下一页" +
		 * nextOrPrev); System.out.println("排序方式" + sortWay);
		 * System.out.println(informationService.getTotalPage());
		 */

		// System.out.println(infoList);
		currentPage = informationService.getNewPage(currentPage, nextOrPrev);
		
		newInfo = informationService.getNewInfo(); 
		
		all = informationService.getAll();

		totalPage = informationService.getTotalPage();

		return "find_or_search_succ";
	}

}
